import time
from alg import Solution
from gen import generate_test_cases

def test_solution():
    solution = Solution()
    
    # 测试用例1
    height1 = [0,1,0,2,1,0,1,3,2,1,2,1]
    print("测试用例1:", height1)
    print("动态规划解法结果:", solution.trap_dp(height1))
    print()
    
    # 测试用例2
    height2 = [4,2,0,3,2,5]
    print("测试用例2:", height2)
    print("动态规划解法结果:", solution.trap_dp(height2))
    print()

def performance_test():
    solution = Solution()
    test_cases = generate_test_cases(num_cases=10, min_length=1000, max_length=10000)
    
    print("性能测试结果：")
    start_time = time.time()
    for case in test_cases:
        solution.trap_dp(case)
    end_time = time.time()
    print(f"动态规划解法平均耗时: {(end_time - start_time) / len(test_cases):.6f}秒")

if __name__ == "__main__":
    print("=== 正确性测试 ===")
    test_solution()
    print("\n=== 性能测试 ===")
    performance_test() 